import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

const path = require("path");
// function pathResolve(dir) {
//   return path.resolve(process.cwd(), ".", dir);
// }

// https://vitejs.dev/config/
export default defineConfig({
  base: "./",
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: [
      {
        find: "@",
        replacement: path.resolve(__dirname, "src"),
      },
      {
        find: "components",
        replacement: path.resolve(__dirname, "src/components"),
      },
      {
        find: "mock",
        replacement: path.resolve(__dirname, "src/mock"),
      },
      {
        find: "router",
        replacement: path.resolve(__dirname, "src/router"),
      },
      {
        find: "store",
        replacement: path.resolve(__dirname, "src/store"),
      },
      {
        find: "views",
        replacement: path.resolve(__dirname, "src/views"),
      },
      {
        find: "locales",
        replacement: path.resolve(__dirname, "src/locales"),
      },
      {
        find: "utils",
        replacement: path.resolve(__dirname, "src/utils"),
      },
      {
        find: "api",
        replacement: path.resolve(__dirname, "src/api"),
      },
      // {
      //   find: /\/#\//,
      //   replacement: pathResolve("myblog") + "/",
      // },
    ],
  },

  server: {
    port: 3000,
    // open: true,
    proxy: {
      "^/publics": {
        target: "http://192.168.0.151:2888/",
        changeOrigin: true,
        cors: true,
        // rewrite: (path) => path.replace(/^\/\/publics/, "publics"),
      },
      "^/swatches": {
        target: "http://192.168.0.151:2888/",
        changeOrigin: true,
        cors: true,
        // rewrite: (path) => path.replace(/^\/api2/, ""),
      },
    },
  },
});
